package br.com.fafica.sisape.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import java.awt.TextArea;
import javax.swing.JButton;

import br.com.fafica.sisape.control.ControllerPrincipal;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;
import java.util.ResourceBundle.Control;
import javax.swing.ImageIcon;

public class TelaCadastrarExames extends JFrame {

	private JPanel contentPane;
	static JTextField txt_dataExame;
	static JTextField txt_hospitalClinica;
	static JTextField txt_tipoExame;
	static JTextField text_medico;
	static TextArea textResultado;
	static Integer codAletrar;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TelaCadastrarExames frame = new TelaCadastrarExames();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TelaCadastrarExames() {
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 840, 540);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblExames = new JLabel("Exames");
		lblExames.setForeground(new Color(0, 0, 128));
		lblExames.setFont(new Font("Franklin Gothic Medium Cond", Font.PLAIN, 25));
		lblExames.setBounds(77, 22, 85, 34);
		contentPane.add(lblExames);
		
		JLabel lblDataDoExame = new JLabel("Data do Exame:");
		lblDataDoExame.setHorizontalAlignment(SwingConstants.RIGHT);
		lblDataDoExame.setFont(new Font("Arial", Font.PLAIN, 14));
		lblDataDoExame.setBounds(106, 76, 124, 19);
		contentPane.add(lblDataDoExame);
		
		txt_dataExame = new JTextField();
		txt_dataExame.setFont(new Font("Arial", Font.PLAIN, 14));
		txt_dataExame.setColumns(10);
		txt_dataExame.setBounds(240, 73, 124, 23);
		contentPane.add(txt_dataExame);
		
		JLabel label_2 = new JLabel("Hospital/Cl\u00EDnica:");
		label_2.setHorizontalAlignment(SwingConstants.RIGHT);
		label_2.setFont(new Font("Arial", Font.PLAIN, 14));
		label_2.setBounds(106, 109, 124, 19);
		contentPane.add(label_2);
		
		txt_hospitalClinica = new JTextField();
		txt_hospitalClinica.setFont(new Font("Arial", Font.PLAIN, 14));
		txt_hospitalClinica.setColumns(10);
		txt_hospitalClinica.setBounds(240, 106, 305, 23);
		contentPane.add(txt_hospitalClinica);
		
		JLabel lblResultado = new JLabel("Resultado:");
		lblResultado.setHorizontalAlignment(SwingConstants.RIGHT);
		lblResultado.setFont(new Font("Arial", Font.PLAIN, 14));
		lblResultado.setBounds(150, 212, 80, 19);
		contentPane.add(lblResultado);
		
		textResultado = new TextArea();
		textResultado.setBounds(238, 212, 380, 189);
		contentPane.add(textResultado);
		
		JLabel lblTipoDoExame = new JLabel("Tipo do Exame:");
		lblTipoDoExame.setHorizontalAlignment(SwingConstants.RIGHT);
		lblTipoDoExame.setFont(new Font("Arial", Font.PLAIN, 14));
		lblTipoDoExame.setBounds(106, 173, 124, 19);
		contentPane.add(lblTipoDoExame);
		
		txt_tipoExame = new JTextField();
		txt_tipoExame.setFont(new Font("Arial", Font.PLAIN, 14));
		txt_tipoExame.setColumns(10);
		txt_tipoExame.setBounds(240, 171, 170, 23);
		contentPane.add(txt_tipoExame);
		
		JButton btnSalvar = new JButton("Salvar");
		btnSalvar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String dataExame = txt_dataExame.getText();
				String local = txt_hospitalClinica.getText();
				String medico = text_medico.getText();
				String tipoExame = txt_tipoExame.getText();
				String resultado = textResultado.getText();
				ControllerPrincipal control = new ControllerPrincipal();
				control.InserirExames(dataExame, local, medico, tipoExame, resultado);
				TelaMensagemSalvar telaMensagem = new TelaMensagemSalvar();
				telaMensagem.setLocationRelativeTo(null);
				telaMensagem.setVisible(true);
				txt_dataExame.setText("");
				txt_hospitalClinica.setText("");
				text_medico.setText("");
				txt_tipoExame.setText("");
				textResultado.setText("");
			}
		});
		btnSalvar.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnSalvar.setBounds(482, 428, 100, 43);
		contentPane.add(btnSalvar);
		
		JButton btnSair = new JButton("Sair");
		btnSair.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		btnSair.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnSair.setBounds(592, 428, 100, 43);
		contentPane.add(btnSair);
		
		JButton button_2 = new JButton("Deletar");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String dataExame = txt_dataExame.getText();
				String local = txt_hospitalClinica.getText();
				String medico = text_medico.getText();
				String tipoExame = txt_tipoExame.getText();
				String resultado = textResultado.getText();
				ControllerPrincipal control = new ControllerPrincipal();
				try {
					control.deletarExames(codAletrar, dataExame, local, medico, tipoExame, resultado);
					TelaMensagemDeletar telaMensagem = new TelaMensagemDeletar();
					telaMensagem.setLocationRelativeTo(null);
					telaMensagem.setVisible(true);
					txt_dataExame.setText("");
					txt_hospitalClinica.setText("");
					text_medico.setText("");
					txt_tipoExame.setText("");
					textResultado.setText("");
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		});
		button_2.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button_2.setBackground(Color.WHITE);
		button_2.setBounds(372, 428, 100, 43);
		contentPane.add(button_2);
		
		JButton button_3 = new JButton("Editar");
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String dataExame = txt_dataExame.getText();
				String local = txt_hospitalClinica.getText();
				String medico = text_medico.getText();
				String tipoExame = txt_tipoExame.getText();
				String resultado = textResultado.getText();
				ControllerPrincipal control = new ControllerPrincipal();
				try {
					control.editarExames(codAletrar, dataExame, local, medico, tipoExame, resultado);
					TelaMensagemSalvar telaMensagem = new TelaMensagemSalvar();
					telaMensagem.setLocationRelativeTo(null);
					telaMensagem.setVisible(true);
					txt_dataExame.setText("");
					txt_hospitalClinica.setText("");
					text_medico.setText("");
					txt_tipoExame.setText("");
					textResultado.setText("");
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		});
		button_3.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button_3.setBackground(Color.WHITE);
		button_3.setBounds(260, 428, 100, 43);
		contentPane.add(button_3);
		
		JButton button_4 = new JButton("Localizar");
		button_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				TelaListarExames telaListaExames = new TelaListarExames();
				telaListaExames.setLocationRelativeTo(null);
				telaListaExames.setVisible(true);
			}
		});
		button_4.setFont(new Font("Tahoma", Font.PLAIN, 16));
		button_4.setBackground(Color.WHITE);
		button_4.setBounds(150, 428, 100, 43);
		contentPane.add(button_4);
		
		JLabel lblMedico = new JLabel("M\u00E9dico:");
		lblMedico.setHorizontalAlignment(SwingConstants.RIGHT);
		lblMedico.setFont(new Font("Arial", Font.PLAIN, 14));
		lblMedico.setBounds(106, 141, 124, 19);
		contentPane.add(lblMedico);
		
		text_medico = new JTextField();
		text_medico.setFont(new Font("Arial", Font.PLAIN, 14));
		text_medico.setColumns(10);
		text_medico.setBounds(240, 139, 305, 23);
		contentPane.add(text_medico);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon("arquivos\\FundoCadastros.png"));
		label.setBounds(0, 0, 834, 511);
		contentPane.add(label);
	}

}
